/*
 *所有关于BomMaster类的业务代码应在此处编写
*可使用repository.调用常用方法，获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*BomMasterService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using iMES.Core.BaseProvider;
using iMES.Core.Extensions.AutofacManager;
using iMES.Entity.DomainModels;
using System.Linq;
using iMES.Core.Utilities;
using System.Linq.Expressions;
using iMES.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using YUN.LReport.IRepositories;
using iMES.Core.Enums;
using System.Collections.Generic;
using System.Threading.Tasks;
using System;
using YUN.LReport.Repositories;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using iMES.Custom.IRepositories;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;

namespace YUN.LReport.Services
{
    public partial class BomMasterService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly IBomMasterRepository _repository;//访问数据库
        private readonly IMaterialMasterRepository _materialrepository;//访问数据库
        private readonly IProcessRouteRepository _processrepository;//访问数据库
        private readonly IBase_NumberRuleRepository _numberRuleRepository;//自定义编码规则访问数据库
        private readonly IBomComponentRelationRepository _bomcomponentrelationRepository;//BOM配件访问数据库
        private readonly IBomProcessRouteRelationRepository _bomprocessrouteRepository;//BOM配件访问数据库

        [ActivatorUtilitiesConstructor]
        public BomMasterService(
            IBomMasterRepository dbRepository,
            IHttpContextAccessor httpContextAccessor,
            IMaterialMasterRepository materialrepository,
            IProcessRouteRepository processrepository,
            IBase_NumberRuleRepository numberRuleRepository,
            IBomComponentRelationRepository bomcomponentrelationRepository,
            IBomProcessRouteRelationRepository bomprocessrouteRepository
            )
        : base(dbRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _repository = dbRepository;
            _materialrepository = materialrepository;
            _processrepository = processrepository;
            _numberRuleRepository = numberRuleRepository;
            _bomcomponentrelationRepository = bomcomponentrelationRepository;
            _bomprocessrouteRepository = bomprocessrouteRepository;
            //多租户会用到这init代码，其他情况可以不用
            //base.Init(dbRepository);
        }
        /// <summary>
        /// 自定义更新从表操作
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public override WebResponseContent Update(SaveModel saveModel)
        {
            //取出校验完成后的从表1.2的数据
            TableExtra tableExtra = saveModel.Extra.ToString().DeserializeObject<TableExtra>();

            //保存到数据库前
            UpdateOnExecuting = (BomMaster plan, object obj, object obj2, List<object> list) =>
            {
                return WebResponseContent.Instance.OK();
            };

            //App_ReportPrice 此处已经提交了数据库，处于事务中
            UpdateOnExecuted = (BomMaster plan, object obj, object obj2, List<object> list) =>
            {
                //在此操作tableExtra从表信息
                List<BomComponentRelation> newsList = tableExtra.Table1List.Select(s => new BomComponentRelation
                {
                    RelationId = s.RelationId,
                    BomId = s.BomId,
                    Quantity = s.Quantity,
                    LossRate = s.LossRate
                }).ToList();

                //id=0的默认为新增的数据
                List<BomComponentRelation> addList = newsList.Where(x => x.RelationId == new Guid("00000000-0000-0000-0000-000000000000")).ToList();
                //设置默认创建人信息
                addList.ForEach(x => { x.SetCreateDefaultVal(); });

                //获取所有编辑行
                List<Guid> editIds = newsList.Where(x => x.RelationId != new Guid("00000000-0000-0000-0000-000000000000")).Select(s => s.RelationId).ToList();
                addList.ForEach(x => { x.SetModifyDefaultVal(); });
                //从数据库查询编辑的行是否存在，如果数据库不存在，执行修改操作会异常
                List<Guid> existsIds = BomComponentRelationRepository.Instance.FindAsIQueryable(x => editIds.Contains(x.RelationId)).Select(s => s.RelationId).ToList();

                //获取实际可以修改的数据
                List<BomComponentRelation> updateList = newsList.Where(x => existsIds.Contains(x.RelationId)).ToList();

                //设置默认修改人信息
                updateList.ForEach(x => { x.SetModifyDefaultVal(); });
                //新增
                repository.AddRange(addList);
                //修改(第二个参数指定要修改的字段,第三个参数执行保存)
                repository.UpdateRange(updateList, x => new { x.Quantity, x.LossRate});
                //点检保养项目
                List<BomProcessRouteRelation> newsList2 = tableExtra.Table2List.Select(s => new BomProcessRouteRelation
                {
                    RelationId = s.RelationId,
                    UnitWorkload = s.UnitWorkload,
                    ResponsiblePerson = s.ResponsiblePerson,
                    Department = s.Department,
                    Remark = s.Remark,
                }).ToList();

                //id=0的默认为新增的数据
                List<BomProcessRouteRelation> addList2 = newsList2.Where(x => x.RelationId == new Guid("00000000-0000-0000-0000-000000000000")).ToList();
                //设置默认创建人信息
                addList2.ForEach(x => { x.SetCreateDefaultVal(); });

                //获取所有编辑行
                List<Guid> editIds2 = newsList2.Where(x => x.RelationId != new Guid("00000000-0000-0000-0000-000000000000")).Select(s => s.RelationId).ToList();
                addList2.ForEach(x => { x.SetModifyDefaultVal(); });
                //从数据库查询编辑的行是否存在，如果数据库不存在，执行修改操作会异常
                List<Guid> existsIds2 = BomProcessRouteRelationRepository.Instance.FindAsIQueryable(x => editIds2.Contains(x.RelationId)).Select(s => s.RelationId).ToList();

                //获取实际可以修改的数据
                List<BomProcessRouteRelation> updateList2 = newsList2.Where(x => existsIds2.Contains(x.RelationId)).ToList();

                //设置默认修改人信息
                updateList2.ForEach(x => { x.SetModifyDefaultVal(); });
                //新增
                repository.AddRange(addList2);
                //修改(第二个参数指定要修改的字段,第三个参数执行保存)
                repository.UpdateRange(updateList2, x => new { x.UnitWorkload, x.ResponsiblePerson, x.Department, x.Remark});
                //最终保存
                repository.SaveChanges();
                return WebResponseContent.Instance.OK();
            };
            return base.Update(saveModel);
        }
        /// <summary>
        /// 获取table1的数据
        /// </summary>
        /// <param name="loadData"></param>
        /// <returns></returns>
        public async Task<object> GetTable1Data(PageDataOptions loadData)
        {
            //Equip_SpotMaintPlanModelBody.vue中loadTableBefore方法查询前给loadData.Value写入的值
            List<where> list = loadData.Wheres.DeserializeObject<List<where>>();
            //获取查询到的总和数
            int total = await BomComponentRelationRepository.Instance.FindAsIQueryable(x => x.BomId == new Guid(list[0].value)).CountAsync();

            var data = await BomComponentRelationRepository.Instance
                //这里可以自己查询条件，从 loadData.Value找前台自定义传的查询条件
                .FindAsIQueryable(x => x.BomId == new Guid(list[0].value))
                //分页
                .TakeOrderByPage(1, 10, x => new Dictionary<object, QueryOrderBy>() { { x.CreateDate, QueryOrderBy.Desc } })
                .Select(s => new { s.RelationId,s.MaterialId,s.MaterialCode, s.MaterialName, s.MaterialModel,s.Quantity,s.UnitName, s.Brand, s.PurchaseUnitPrice, s.LossRate })
                .ToListAsync();
            object gridData = new { rows = data, total };
            return gridData;
        }
        /// <summary>
        /// 获取table2的数据
        /// </summary>
        /// <param name="loadData"></param>
        /// <returns></returns>
        public async Task<object> GetTable2Data(PageDataOptions loadData)
        {
            //Equip_SpotMaintPlanModelBody.vue中loadTableBefore方法查询前给loadData.Value写入的值
            //获取查询到的总和数
            List<where> list = loadData.Wheres.DeserializeObject<List<where>>();
            //获取查询到的总和数
            int total = await repository.DbContext.Set<BomProcessRouteRelation>().Where(x => x.BomId == new Guid(list[0].value)).CountAsync();
            //从 loadData.Value取查询条件，分页等信息
            //这里可以自己查询条件，从 loadData.Value找前台自定义传的查询条件
            var data = await repository.DbContext.Set<BomProcessRouteRelation>().Where(x => x.BomId == new Guid(list[0].value))
                //分页
                .TakeOrderByPage(1, 10, x => new Dictionary<object, QueryOrderBy>() { { x.CreateDate, QueryOrderBy.Desc } })
                .Select(s => new {s.RelationId,s.ResponsiblePerson,s.Department , s.RouteId, s.RouteName, s.RouteCode, s.Status, s.CreatorId, s.Remark, s.CreatorName, s.ModifyDate, s.CreateDate, s.ModifierName, s.ModifierId ,s.UnitWorkload})
                .ToListAsync();
            object gridData = new { rows = data, total };
            return gridData;
        }
        WebResponseContent webResponse = new WebResponseContent();

        /// <summary>
        /// 自定义保存从表数据逻辑
        /// </summary>
        /// <param name="saveDataModel"></param>
        /// <returns></returns>
        public override WebResponseContent Add(SaveModel saveDataModel)
        {
            //取出校验完成后的从表1.2的数据
            TableExtra tableExtra = saveDataModel.Extra.ToString().DeserializeObject<TableExtra>();
            //保存到数据库前
            AddOnExecuting = (BomMaster bom, object obj) =>
            {
                if (string.IsNullOrWhiteSpace(bom.BomNumber))
                    bom.BomNumber = GetProductionWorkOrderCode();
                //如果返回false,后面代码不会再执行
                if (repository.Exists(x => x.BomNumber == bom.BomNumber))
                {
                    return webResponse.Error("BOM工单编号已存在");
                }
                bom.SetCreateDefaultVal();
                return WebResponseContent.Instance.OK();
            };
            //Equip_SpotMaintPlan 此处已经提交了数据库，处于事务中
            AddOnExecuted = (BomMaster bom, object obj) =>
            {
                //在此操作tableExtra从表信息
                List<BomComponentRelation> newsList = tableExtra.Table1List.Select(s => new BomComponentRelation
                {
                    RelationId=s.RelationId,
                    BomId = bom.BomId,
                    MaterialId = s.MaterialId,
                    MaterialModel  = s.MaterialModel,
                    Brand  = s.Brand,
                    MaterialName=s.MaterialName,
                    Quantity = s.Quantity,
                    PurchaseUnitPrice = s.PurchaseUnitPrice,
                    MaterialCode = s.MaterialCode,
                    UnitName = s.UnitName,
                    LossRate = s.LossRate,
                    Remark = s.Remark,
                    CreateDate=DateTime.Now
                }).ToList();

                //id=0的默认为新增的数据
                List<BomComponentRelation> addList = newsList.Where(x => x.RelationId == new Guid("00000000-0000-0000-0000-000000000000")).ToList();
                //设置默认创建人信息
                addList.ForEach(x => { x.SetCreateDefaultVal(); });
                //新增
                repository.AddRange(addList);
                //点检保养项目
                List<BomProcessRouteRelation> newsList2 = tableExtra.Table2List.Select(s => new BomProcessRouteRelation
                {
                    RelationId = s.RelationId,
                    BomId = bom.BomId,
                    RouteId = s.RouteId,
                    RouteName = s.RouteName,
                    RouteCode = s.RouteCode,
                    Status = s.Status,
                    Remark = s.Remark,
                    ResponsiblePerson=s.ResponsiblePerson,
                    Department=s.Department,
                    UnitWorkload=s.UnitWorkload,
                    CreateDate=DateTime.Now,
                    CreatorId=s.CreatorId,
                    CreatorName=s.CreatorName
                }).ToList();

                //id=0的默认为新增的数据
                List<BomProcessRouteRelation> addList2 = newsList2.Where(x => x.RelationId == new Guid("00000000-0000-0000-0000-000000000000")).ToList();
                //设置默认创建人信息
                addList2.ForEach(x => { x.SetCreateDefaultVal(); });
                //新增
                repository.AddRange(addList2);
                //最终保存
                repository.SaveChanges();
                return WebResponseContent.Instance.OK();
            };
            return base.Add(saveDataModel);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="keys"></param>
        /// <param name="delList"></param>
        /// <returns></returns>
        public override WebResponseContent Del(object[] keys, bool delList = true)
        {
            for (int i = 0; i < keys.Length; i++)
            {
                List<object> idsDevice = BomComponentRelationRepository.Instance.FindAsIQueryable(x => x.RelationId == new Guid(keys[i].ToString())).Select(s => (object)s.RelationId).ToList();
                List<object> idsProject = BomProcessRouteRelationRepository.Instance.FindAsIQueryable(x => x.RelationId == new Guid(keys[i].ToString())).Select(s => (object)s.RelationId).ToList();
                object[] arrayDevice = idsDevice.ToArray();
                object[] arrayProject = idsProject.ToArray();
                _bomcomponentrelationRepository.DeleteWithKeys(arrayDevice, true);
                _bomprocessrouteRepository.DeleteWithKeys(arrayProject, true);
            }
            //最终保存
            repository.SaveChanges();
            return base.Del(keys, true);
        }
        public override PageGridData<BomMaster> GetPageData(PageDataOptions options)
        {

            // 2. 设置默认值和验证
            if (options.Page <= 0) options.Page = 1;
            if (options.Rows <= 0) options.Rows = 10;  // 设置一个默认的页大小
                                                       // 创建一个匿名类型来包含所有需要的字段
            var query = from bom in _repository.DbContext.Set<BomMaster>()
                        join product in _repository.DbContext.Set<ProductInfoA>()
                         on bom.ProductId equals product.ProductId
                        select new
                        {
                            // Bom_Master字段
                            bom.BomId,
                            bom.BomNumber,
                            bom.ProductId,
                            bom.Version,
                            bom.Status,
                            bom.CreatorId,
                            bom.CreatorName,
                            bom.CreateDate,
                            bom.ModifierId,
                            bom.ModifierName,
                            bom.ModifyDate,
                            bom.Remark,
                            bom.IsDefaultBOM,
                            bom.ArtifactType,
                            bom.Output,
                            bom.BOMReportTitle,
                            bom.Attachment,
                            // Product_1字段
                            product.ProductCode,
                            product.ProductName,
                            product.ProductUPId,
                        };

            int total = query.Count();

            var data = query.Skip((options.Page - 1) * options.Rows)
                            .Take(options.Rows)
                            .ToList()
                            .Select(x => new BomMaster
                            {
                                BomId = x.BomId,
                                BomNumber = x.BomNumber,
                                ProductId = x.ProductId,
                                Version = x.Version,
                                Status = x.Status,
                                CreatorId = x.CreatorId,
                                CreatorName = x.CreatorName,
                                CreateDate = x.CreateDate,
                                ModifierId = x.ModifierId,
                                ModifierName = x.ModifierName,
                                ModifyDate = x.ModifyDate,
                                Remark = x.Remark,
                                IsDefaultBOM = x.IsDefaultBOM,
                                ArtifactType = x.ArtifactType,
                                Output = x.Output,
                                BOMReportTitle = x.BOMReportTitle,
                                Attachment = x.Attachment,
                                ProductCode = x.ProductCode,
                                ProductName = x.ProductName,
                                ProductUPId = x.ProductUPId,
                            })
                            .ToList();

            return new PageGridData<BomMaster>
            {
                rows = data,
                total = total
            };
        }
        /// <summary>
        /// 自动生成我的工单编号
        /// </summary>
        /// <returns></returns>
        public string GetProductionWorkOrderCode()
        {
            DateTime dateNow = (DateTime)DateTime.Now.ToString("yyyy-MM-dd").GetDateTime();
            //查询当天最新的订单号
            string defectItemCode = repository.FindAsIQueryable(x => x.CreateDate > dateNow && x.BomNumber.Length >= 8)
                .OrderByDescending(x => x.BomNumber)
                .Select(s => s.BomNumber)
                .FirstOrDefault();
            Base_NumberRule numberRule = _numberRuleRepository.FindAsIQueryable(x => x.FormCode == "MBOMRNumber")
                .OrderByDescending(x => x.CreateDate)
                .FirstOrDefault();
            if (numberRule != null)
            {
                string rule = numberRule.Prefix + DateTime.Now.ToString(numberRule.SubmitTime.Replace("hh", "HH"));
                if (string.IsNullOrEmpty(defectItemCode))
                {
                    rule += "1".PadLeft(numberRule.SerialNumber, '0');
                }
                else
                {
                    rule += (defectItemCode.Substring(defectItemCode.Length - numberRule.SerialNumber).GetInt() + 1).ToString("0".PadLeft(numberRule.SerialNumber, '0'));
                }
                return rule;
            }
            else //如果自定义序号配置项不存在，则使用日期生成
            {
                return DateTime.Now.ToString("yyyyMMddHHmmssffff");
            }
        }
    }
    public class Table1
    {
        /// <summary>
        ///关系ID
        /// </summary>
        [Display(Name = "关系ID")]
        [MaxLength(50)]
        [Column(TypeName = "uniqueidentifier")]
        [Required(AllowEmptyStrings = false)]
        public Guid RelationId { get; set; }

        /// <summary>
        ///关联BOM主表ID
        /// </summary>
        [Display(Name = "关联BOM主表ID")]
        [MaxLength(50)]
        [Column(TypeName = "uniqueidentifier")]
        [Required(AllowEmptyStrings = false)]
        public Guid BomId { get; set; }
        /// <summary>
        ///品牌
        /// </summary>
        [Display(Name = "品牌")]
        [MaxLength(100)]
        [Column(TypeName = "varchar(100)")]
        [Editable(true)]
        public string Brand { get; set; }

        /// <summary>
        ///关联配件主表ID
        /// </summary>
        [Display(Name = "关联配件主表ID")]
        [MaxLength(50)]
        [Column(TypeName = "uniqueidentifier")]
        [Required(AllowEmptyStrings = false)]
        public Guid MaterialId { get; set; }

        /// <summary>
        /// 物料编码
        /// </summary>
        [Display(Name = " 物料编码")]
        [MaxLength(50)]
        [Column(TypeName = "varchar(50)")]
        [Editable(true)]
        [Required(AllowEmptyStrings = false)]
        public string MaterialCode { get; set; }

        /// <summary>
        ///物料名称
        /// </summary>
        [Display(Name = "物料名称")]
        [MaxLength(100)]
        [Column(TypeName = "varchar(100)")]
        [Editable(true)]
        public string MaterialName { get; set; }

        /// <summary>
        ///规格型号
        /// </summary>
        [Display(Name = "规格型号")]
        [MaxLength(100)]
        [Column(TypeName = "varchar(100)")]
        [Editable(true)]
        public string MaterialModel { get; set; }


        /// <summary>
        ///配件数量
        /// </summary>
        [Display(Name = "配件数量")]
        [DisplayFormat(DataFormatString = "18,6")]
        [Column(TypeName = "decimal")]
        public decimal? Quantity { get; set; }

        /// <summary>
        ///创建日期
        /// </summary>
        [Display(Name = "创建日期")]
        [Column(TypeName = "datetime")]
        public DateTime? CreateDate { get; set; }

        /// <summary>
        ///采购单价
        /// </summary>
        [Display(Name = "采购单价")]
        [DisplayFormat(DataFormatString = "10,2")]
        [Column(TypeName = "decimal")]
        [Required(AllowEmptyStrings = false)]
        public decimal PurchaseUnitPrice { get; set; }

        /// <summary>
        ///单位名称
        /// </summary>
        [Display(Name = "单位名称")]
        [MaxLength(50)]
        [Column(TypeName = "varchar(50)")]
        public string UnitName { get; set; }

        /// <summary>
        ///损耗率(%)
        /// </summary>
        [Display(Name = "损耗率(%)")]
        [DisplayFormat(DataFormatString = "8,2")]
        [Column(TypeName = "decimal")]
        public decimal? LossRate { get; set; }


        /// <summary>
        ///备注说明
        /// </summary>
        [Display(Name = "备注说明")]
        [MaxLength(500)]
        [Column(TypeName = "varchar(500)")]
        public string Remark { get; set; }
    }
    public class Table2
    {
        /// <summary>
        ///关系ID
        /// </summary>
        [Display(Name = "关系ID")]
        [MaxLength(50)]
        [Column(TypeName = "uniqueidentifier")]
        [Required(AllowEmptyStrings = false)]
        public Guid RelationId { get; set; }

        /// <summary>
        ///BOM主表ID
        /// </summary>
        [Display(Name = "BOM主表ID")]
        [MaxLength(50)]
        [Column(TypeName = "uniqueidentifier")]
        [Required(AllowEmptyStrings = false)]
        public Guid BomId { get; set; }

        /// <summary>
        ///工艺路线主表ID
        /// </summary>
        [Display(Name = "工艺路线主表ID")]
        [MaxLength(50)]
        [Column(TypeName = "uniqueidentifier")]
        [Required(AllowEmptyStrings = false)]
        public Guid RouteId { get; set; }

        /// <summary>
        ///工艺路线名称
        /// </summary>
        [Display(Name = "工艺路线名称")]
        [MaxLength(100)]
        [Column(TypeName = "varchar(100)")]
        public string RouteName { get; set; }

        /// <summary>
        ///工艺路线编号
        /// </summary>
        [Display(Name = "工艺路线编号")]
        [MaxLength(50)]
        [Column(TypeName = "varchar(50)")]
        public string RouteCode { get; set; }

        ///// <summary>
        /////版本号
        ///// </summary>
        //[Display(Name = "版本号")]
        //[MaxLength(10)]
        //[Column(TypeName = "varchar(10)")]
        //public string VersionNo { get; set; }

        /// <summary>
        ///状态
        /// </summary>
        [Display(Name = "状态")]
        [Column(TypeName = "int")]
        public int? Status { get; set; }

        /// <summary>
        ///创建人ID
        /// </summary>
        [Display(Name = "创建人ID")]
        [MaxLength(50)]
        [Column(TypeName = "varchar(50)")]
        public string CreatorId { get; set; }

        /// <summary>
        ///创建人姓名
        /// </summary>
        [Display(Name = "创建人姓名")]
        [MaxLength(50)]
        [Column(TypeName = "varchar(50)")]
        public string CreatorName { get; set; }

        /// <summary>
        ///创建日期
        /// </summary>
        [Display(Name = "创建日期")]
        [Column(TypeName = "datetime")]
        public DateTime? CreateDate { get; set; }

        /// <summary>
        ///修改人ID
        /// </summary>
        [Display(Name = "修改人ID")]
        [MaxLength(50)]
        [Column(TypeName = "varchar(50)")]
        public string ModifierId { get; set; }

        /// <summary>
        ///修改人姓名
        /// </summary>
        [Display(Name = "修改人姓名")]
        [MaxLength(50)]
        [Column(TypeName = "varchar(50)")]
        public string ModifierName { get; set; }

        /// <summary>
        ///修改日期
        /// </summary>
        [Display(Name = "修改日期")]
        [Column(TypeName = "datetime")]
        public DateTime? ModifyDate { get; set; }

        /// <summary>
        ///备注说明
        /// </summary>
        [Display(Name = "备注说明")]
        [MaxLength(500)]
        [Column(TypeName = "varchar(500)")]
        public string Remark { get; set; }
        /// <summary>
        ///负责人姓名
        /// </summary>
        [Display(Name = "负责人姓名")]
        [MaxLength(50)]
        [Column(TypeName = "varchar(50)")]
        public string ResponsiblePerson { get; set; }

        /// <summary>
        ///部门名称
        /// </summary>
        [Display(Name = "部门名称")]
        [MaxLength(50)]
        [Column(TypeName = "varchar(50)")]
        public string Department { get; set; }
        /// <summary>
        ///单位工作量
        /// </summary>
        [Display(Name = "单位工作量")]
        [Column(TypeName = "int")]
        public int UnitWorkload { get; set; }


    }
    public class TableExtra
    {
        /// <summary>
        /// 从表1
        /// </summary>
        public List<Table1> Table1List { get; set; }

        /// <summary>
        /// 从表2
        /// </summary>
        public List<Table2> Table2List { get; set; }
    }
    public class where
    {
        public string name { get; set; }
        public string value { get; set; }
    }
}
